home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / tstconn.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  5KB  |  173 lines

  1. {$X+,V-,B-}
  2. Program testconn;
  3.  
  4. { Testprogram for the nwConn unit / NwTP 0.6 API. (c) 1993, 1995, R.Spronk }
  5.  
  6. { Purpose: testing of nwConn calls }
  7.  
  8. { Tests the following nwConn functions:
  9.  
  10.   GetConnectionId
  11.   GetConnectionInformation
  12.   GetConnectionNumber
  13.   GetDefaultConnectionId
  14.   GetFileserverName
  15.   GetInternetAddress
  16.   GetObjectConnectionNumbers
  17.   GetPreferredConnectionId
  18.   GetPrimaryConnectionId
  19.   GetWorkstationNodeAddress
  20.   GetUserAtConnection
  21. }
  22.  
  23. Uses nwMisc,nwConn;
  24.  
  25. Procedure Warning(s:string);
  26. begin
  27. writeln(s);
  28. writeln(' ERROR #: $',HexStr(nwConn.Result,2),' (',nwConn.result,')');
  29. writeln;
  30. writeln('...Press <Enter> to Continue..');
  31. readln;
  32. end;
  33.  
  34. Var myConnNumber:byte;
  35.     myConnId    :byte; { connID of server I'm attached to }
  36.     myPhysNode2:TnodeAddress;
  37.     myObjName   :string;
  38.     myObjType   :word;
  39.     myObjId     :longInt;
  40.     myLoginTime :TnovTime;
  41.  
  42.     myAddress:TinternetworkAddress;
  43.  
  44.     nbrOfConn:byte;
  45.     connList :TconnectionList;
  46.  
  47.     objName  :string;
  48.     objType  :word;
  49.     objId    :LongInt;
  50.     LoginTime:TnovTime;
  51.  
  52.     connId    :byte;
  53.     serverName:string;
  54.     routeInfo :string;
  55.  
  56.     t      :byte;
  57.     tempStr:string;
  58.  
  59. begin
  60.  
  61. IF GetConnectionNumber(myConnNumber)
  62.  then writeln('Your connection number is:',myConnNumber)
  63.  else warning('!!! The GetConnectionNumber call failed');
  64.  
  65. IF GetInterNetAddress(myConnNumber,myAddress)
  66.  then begin
  67.       write('Your Netw.:Node:Socket Nbr is: [$');
  68.        for t:=1 to 4 do write(hexStr(myAddress.Net[t],2));
  69.        write(':');
  70.        for t:=1 to 6 do write(HexStr(myAddress.Node[t],2));
  71.       writeln(':',hexstr(myAddress.socket,4),']');
  72.       end
  73.  else warning('!!! GetInterNetAdress failed.');
  74.  
  75.  
  76. IF GetWorkstationNodeAddress(myPhysNode2)
  77.   and (myAddress.Node[6]=myPhysNode2[6])
  78.   and (myAddress.Node[5]=myPhysNode2[5])
  79.   and (myAddress.Node[4]=myPhysNode2[4])
  80.  then { ok }
  81.  else begin
  82.       warning('!!! GetStationadress failed');
  83.       write('returned: $');
  84.         for t:=1 to 6 do write(HexStr(myPhysNode2[t],2));
  85.       end;
  86.  
  87. IF GetConnectionInformation(myConnNumber,
  88.                             myObjName,myObjType,myObjId,myLoginTime)
  89.  then begin
  90.       writeln('You are :',myObjName);
  91.       if myObjType=$1 { OT_USER}
  92.        then writeln(' of object type : USER')
  93.        else writeln(' of object type : $',HexStr(myObjType,4));
  94.       writeln(' with object ID: $',HexStr(myObjId,8));
  95.       NovTime2String(myLoginTime,tempStr);
  96.       writeln(' logged in at ',tempStr);
  97.       end
  98.  else warning('!!! GetConnectionInformation failed.');
  99.  
  100. if NOT (GetUserAtConnection(myConnNumber,tempStr) and (tempStr=myObjName))
  101.  then warning('!!! GetUserAtConnection (2) failed.');
  102.  
  103. IF GetObjectConnectionNumbers(myObjName,1 {OT_USER},
  104.                               nbrOfConn,connList)
  105.  then begin
  106.       writeln('User ',myObjName,' has ',nbrOfConn,' active connection(s).');
  107.       t:=nbrOfConn;
  108.       if t>0
  109.        then begin
  110.             t:=1;
  111.             while t<=nbrOfConn
  112.              do begin
  113.                 writeln('  at connectionNumber:',connList[t]);
  114.                 inc(t);
  115.                 end;
  116.             end;
  117.       end
  118.  else warning('!!! GetObjectConnectionNumbers failed.');
  119.  
  120.  
  121. writeln;
  122. t:=1;
  123. writeln('ConnNbr Name             LoginTime');
  124. WHILE t<250 { nw 3.x / 2.x  100 }
  125. do begin
  126.    IF GetConnectionInformation(t, objName,objType,objId,LoginTime)
  127.     then begin
  128.          PstrCopy(TempStr,objName,15);
  129.          objName:=TempStr;
  130.          NovTime2String(LoginTime,TempStr);
  131.          writeln(t:4,'    ',objName,'  ',TempStr);
  132.          end
  133.     else if nwConn.result<>$FD { bad_station_number / nbr not in use }
  134.          then warning('!!! GetConnectionInformation failed.');
  135.    inc(t);
  136.    end;
  137.  
  138. {*********** connection ID's ( server numbers in server table )************ }
  139.  
  140. { to which server have we been sending all the above requests? }
  141.  
  142. routeInfo:='preferred';
  143. GetPreferredConnectionID(ConnId);
  144.  { if set previously, this server has the highest priority. }
  145.  
  146. if connId=0 { preferred server was not set }
  147.  then begin
  148.       RouteInfo:='default';
  149.       GetDefaultConnectionID(ConnId);
  150.       end;
  151.  { your current default drive is attached to this server }
  152.  
  153. if connId=0
  154.  then begin
  155.       RouteInfo:='primary';
  156.       GetPrimaryConnectionID(ConnId);
  157.       end;
  158.  { the server your shell initially attached to, used if the default drive
  159.    is a local drive. Lowest priority. }
  160.  
  161. { These three calls are also incorporated in the secondary function:
  162.   GetEffectiveConnectionID. }
  163. writeln;
  164. writeln('All requests are routed to the ',RouteInfo,'-server with conn.ID=',connId);
  165.  
  166. GetFileServerName(connId,{out:} serverName);
  167. GetConnectionID(serverName,{out} t);
  168. if t<>connId
  169.  then warning('!!! GetFileServerName and GetConnectionId report different values.')
  170.  else writeln('Name of the server: ',serverName);
  171.  
  172. end.
  173.